package com.ziyueyuwen.xiniao.enums;

import com.ziyueyuwen.xiniao.util.DateUtil;

import java.util.Date;

import static com.ziyueyuwen.xiniao.util.DateUtil.DEFAULT_FORMAT_PATTERN_4;

/**
 * @author wancheng  on 2019/2/21.
 */
public enum ProductPeriodEnum {
    /**
     * 上午
     */
    AM("上午","00:00:00", "11:59:59"),
    /**
     * 下午
     */
    PM("下午","12:00:00", "17:59:59"),
    /**
     * 晚上
     */
    NIGHT("晚上","18:00:00", "23:59:59");

    public static ProductPeriodEnum getProductPeriod(Date date) {
        ProductPeriodEnum res = null;
        for (ProductPeriodEnum e : ProductPeriodEnum.values()) {
            Date beginTime = DateUtil.str2Date(e.getBeginTime(), DEFAULT_FORMAT_PATTERN_4);
            Date endTime = DateUtil.str2Date(e.getEndTime(), DEFAULT_FORMAT_PATTERN_4);
            if (beginTime.getTime() <= date.getTime() && date.getTime() < endTime.getTime()) {
                res = e;
                break;

            }
        }
        return res;
    }
    private String desc;
    private String beginTime;
    private String endTime;

    ProductPeriodEnum(String desc, String beginTime, String endTime) {
        this.desc = desc;
        this.beginTime = beginTime;
        this.endTime = endTime;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
